<template>
  <Dialog v-model="show" @confirm="handleSubmit" title="新增管理员" width="30%">
    <el-form :model="formData" label-width="100px" ref="formRef" :rules="rules">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="formData.name" />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-input v-model="formData.sex" />
      </el-form-item>
      <el-form-item label="身份证号码" prop="idCard">
        <el-input v-model="formData.idCard" />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input v-model="formData.phone" />
      </el-form-item>
      <el-form-item label="所属岗位" prop="job">
        <el-input v-model="formData.job" />
      </el-form-item>
      <el-form-item label="工号" prop="jobNumber">
        <el-input v-model="formData.jobNumber" />
      </el-form-item>
      <el-form-item label="部门名称" prop="department">
        <el-input v-model="formData.department" />
      </el-form-item>
      <el-form-item label="登录密码" prop="password">
        <el-input type="password" v-model="formData.password" />
      </el-form-item>
    </el-form>
  </Dialog>
</template>
<script setup>
import { ref, watch } from "vue";
import Dialog from "@/components/dialog.vue";

const show = defineModel();
const props = defineProps({
  data: {
    type: Object,
    default: () => ({}),
  },
});
watch(show, (val) => {
  if (val) {
    props.data && (formData.value = props.data);
  }
});
const formData = ref({
  name: "",
  sex: "",
  idCard: "",
  phone: "",
  job: "",
  jobNumber: "",
  department: "",
  password: "",
});
const rules = ref({
  name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
  sex: [{ required: true, message: "请输入性别", trigger: "blur" }],
  idCard: [{ required: true, message: "请输入身份证号码", trigger: "blur" }],
  phone: [{ required: true, message: "请输入手机号码", trigger: "blur" }],
  job: [{ required: true, message: "请输入岗位", trigger: "blur" }],
  jobNumber: [{ required: true, message: "请输入工号", trigger: "blur" }],
  department: [{ required: true, message: "请输入部门名称", trigger: "blur" }],
  password: [{ required: true, message: "请输入登录密码", trigger: "blur" }],
});
const formRef = ref();
const handleSubmit = () => {
  formRef.value.validate((valid) => {
    if (valid) {
      console.log("submit!");
    } else {
      console.log("error submit!");
    }
  });
};
</script>
